package com.dwy2002.order.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.dwy2002.enums.rabbit.CourseRabbitConstants.*;
import static com.dwy2002.enums.rabbit.DlxRabbitConstants.DLX_EXCHANGE;
import static com.dwy2002.enums.rabbit.DlxRabbitConstants.DLX_ROUTING_KEY;

/**
 * 课程订单rabbit配置类
 *
 * @author 杜伟毅
 * @version 1.0
 * @since 2025/03/22
 */
@Configuration
public class EnrollmentResponseRabbitConfig {
    @Bean
    public Queue enrollmentResponseQueue() {
        return QueueBuilder.durable(ENROLLMENT_RESPONSE_QUEUE)
                .deadLetterExchange(DLX_EXCHANGE) // 绑定死信交换机
                .deadLetterRoutingKey(DLX_ROUTING_KEY)
                .build();
    }

    @Bean
    public DirectExchange enrollmentResponseExchange() { // 独立的 Direct 交换机
        return new DirectExchange(ENROLLMENT_RESPONSE_EXCHANGE);
    }

    @Bean
    public Binding enrollmentResponseBinding() {
        return BindingBuilder.bind(enrollmentResponseQueue())
                .to(enrollmentResponseExchange())
                .with(ENROLLMENT_RESPONSE_ROUTING_KEY); // 使用专属路由键
    }
}
